package com.baitengsoft.patentapimonitor.api.service.impl;

import com.baitengsoft.patentapimonitor.api.entity.WebMenuEntity;
import com.baitengsoft.patentapimonitor.api.entity.WebRolesEntity;
import com.baitengsoft.patentapimonitor.api.model.MenuModel;
import com.baitengsoft.patentapimonitor.api.service.WebMenuService;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Admin on 2017/12/19.
 */
@Service
public class WebMenuServiceImpl extends BaseServiceImpl<WebMenuEntity> implements WebMenuService{

    @Resource
    Mapper mapper;
    @Override
    public WebMenuEntity searchById(int id) {
        try {
            WebMenuEntity entity= queryById(id);
            return entity;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public List<MenuModel> search() {

        WebMenuEntity entity=new WebMenuEntity();
        entity.setStatus(1);
        List<WebMenuEntity> entities=queryListByWhere(entity);
        if(entities!=null&&entities.size()>0){
            List<MenuModel> models=new ArrayList<>();
            for (WebMenuEntity menuEntity:entities){
                MenuModel model=new MenuModel();
                mapper.map(menuEntity,model);
                models.add(model);
            }
            return models;
        }
        return null;
    }
}
